﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PingTest
{
    public partial class ConfigForm : Form
    {
        public ConfigForm()
        {
            InitializeComponent();
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {
            tbDisconnLost.Text = Config.THRESHOLD_DISCONNECT_LOST_RATE.ToString();
            tbDisconnBuffer.Text = Config.THRESHOLD_DISCONNECT_BUFFER_SIZE.ToString();
            tbGoodLost.Text = Config.THRESHOLD_GOOD_LOST_RATE.ToString();
            tbGoodBuffer.Text = Config.THRESHOLD_GOOD_BUFFER_SIZE.ToString();
            tbGoodLatency.Text = Config.THRESHOLD_GOOD_LATENCY.ToString();
            tbBadLost.Text = Config.THRESHOLD_BAD_LOST_RATE.ToString();
            tbBadBuffer.Text = Config.THRESHOLD_BAD_BUFFER_SIZE.ToString();
            tbBadLatency.Text = Config.THRESHOLD_BAD_LATENCY.ToString();
            //
            tbTitle.Text = Config.MAIN_FORM_TITLE;
            tbInterval.Text = Config.PING_INTERVAL.ToString();
            tbMaxBuffer.Text = Config.MAX_BUFFER_SIZE.ToString();
            //
            refresh();
        }

        private void refresh()
        {
            lbGoodColor.BackColor = Config.COLOR_GOOD;
            lbBadColor.BackColor = Config.COLOR_BAD;
            lbOtherColor.BackColor = Config.COLOR_OTHER;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Config.THRESHOLD_DISCONNECT_LOST_RATE = int.Parse(tbDisconnLost.Text);
            Config.THRESHOLD_DISCONNECT_BUFFER_SIZE = int.Parse(tbDisconnBuffer.Text);
            Config.THRESHOLD_GOOD_LOST_RATE = int.Parse(tbGoodLost.Text);
            Config.THRESHOLD_GOOD_BUFFER_SIZE = int.Parse(tbGoodBuffer.Text);
            Config.THRESHOLD_GOOD_LATENCY = int.Parse(tbGoodLatency.Text);
            Config.THRESHOLD_BAD_LOST_RATE = int.Parse(tbBadLost.Text);
            Config.THRESHOLD_BAD_BUFFER_SIZE = int.Parse(tbBadBuffer.Text);
            Config.THRESHOLD_BAD_LATENCY = int.Parse(tbBadLatency.Text);
            //
            Config.MAIN_FORM_TITLE = tbTitle.Text.Trim();
            Config.PING_INTERVAL = int.Parse(tbInterval.Text);
            Config.MAX_BUFFER_SIZE = int.Parse(tbMaxBuffer.Text);
        }

        private void btnSelectColor1_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                Config.COLOR_GOOD = colorDialog1.Color;
                refresh();
            }
        }

        private void btnSelectColor2_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                Config.COLOR_BAD = colorDialog1.Color;
                refresh();
            }
        }

        private void btnSelectColor3_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                Config.COLOR_OTHER = colorDialog1.Color;
                refresh();
            }
        }

    }
}
